import axios from 'axios'
import store from '@/vuex/store'
import { Toast } from 'mint-ui'
let API
const BASE_URL = 'http://scm.szwego.cn:9015'

const
  URL_LOGIN = '/Scm/Account/AntLogin',
  URL_WX_LOGIN = '/Scm/Account/WxLogin',
	URL_GET_SAMPLE_DETAIL = '/Scm/Sample/Get',//获取样衣详情
	URL_GET_SAMPLE_IMGS ='/Scm/YYZPSH/QuerySampleImg',//获取样衣图片列表
	URL_GET_SUPPLIER_CERTIFICATE_DETAIL = '/VScm/GYSBase/Get',
	URL_UPLOAD_SUPPLIER_CERTIFICATE ='/VScm/GYSBase/Upload',
	URL_UPDATE_SUPPLIER_CERTIFICATE ='/VScm/GYSBase/Edit',
	URL_GET_SUPPLIER_CERTIFICATE_LIST = '/VScm/GYSBase/GetList',
	URL_BAND_LIST = '/VScm/BDXQ/QueryBDXQList',
	URL_BAND_DETAIL = '/VScm/BDXQ/Get',
	URL_ADD_SAMPLE_COAT = '/VScm/YYSQ/Create',
	URL_GET_BASE_BAND_LIST = '/Dict/GetBand',
	URL_GET_BASE_VENDER_LIST = '/Dict/GetVender',
	URL_GET_BASE_STYLY_LIST = '/Dict/GetStyle',
	URL_GET_BASE_CATEGORY_LIST = '/Dict/GetSysCategory',
	URL_GET_PRIMARY_LIST = '/VScm/YYCXD/QueryYYCXDList',
	URL_GET_PRIMARY_DETAIL = '/VScm/YYCXD/GetExpressDetial',
	URL_GET_PRIMARY_EXPRESS = '/VScm/YYCXD/GetYJExpress',
	URL_SEND_SAMPLE = '/VScm/YYCXD/SendSample',
	URL_GET_ELIMINATE_LIST = '/VScm/TTYY/QueryTTYYList',
	URL_TACK_SAMPLE = '/VScm/TTYY/TakeSample',
	URL_TACK_ONE_SAMPLE = '/VScm/TTYY/TakeOneSample',
	URL_GET_SECONDE_INSTANCE_LIST = '/VScm/ESZLBC/QueryESZLBCList',
	URL_GET_SECONDE_INSTANCE_SAVE = '/VScm/ESZLBC/Edit',
	URL_GET_APPLY_LIST = '/VScm/YYSQ/QueryYYSQList',
	URL_UPLOAD = '/VScm/YYSQ/Upload',
	URL_BAND_CREATE = '/VScm/YYSQ/Create',
	URL_BAND_EDIT = '/VScm/YYSQ/Edit',
	URL_GET_STATE_TREE = '/Scm/Dict/QueryFlagTree',
	URL_GET_WORK_STATE = '/VScm/YYSQ/GetWrokStatus',
	URL_BAND_SUBMIT = '/VScm/YYSQ/Submit',
	URL_GET_COLOR = '/Scm/Dict/GetColor',
	URL_GET_SIZE = '/Scm/Dict/GetSize',
	URL_SUBMIT_DETAIL = '/VScm/YYCXD/SubmitDetial',
	URL_GET_EXPRESS = '/Scm/YYCXSH/ExpList',
	URL_GET_MENU = '/Home/GetTreeByMobile',
	URL_GET_IMG_LIST = '/Scm/YYZPSH/QueryYYZPSHList',
	URL_GET_SAMPLE_CHECK_LIST = '/Scm/YYZPSH/QueryCheckList',
	URL_GET_BASE_FLAG_LIST = '/Scm/YYZPSH/GetBaseFalg',
	URL_GET_PHOTO_CHECK_LIST = '/Scm/Dict/QueryPhotoCheckList',
	URL_CHECK_PHOTO = '/Scm/YYZPSH/CheckPhoto',
	URL_GET_PUSH_LIST = '/Scm/HXFB/QueryHXFBList',
	URL_GET_PUSH_STATUS_LIST = '/Scm/HXFB/GetPushFalg',
	URL_PUSH_PUBLISH = '/Scm/HXFB/Publish',
	URL_AUDIT_LIKE = '/Scm/YYHX/Like',
	URL_AUDIT_UNLIKE = '/Scm/YYHX/UnLike',
	URL_GET_AUDIT_LIST = '/Scm/YYHX/QueryYYHXList',
	URL_GET_RESOLVE_LIST = '/Scm/YYHXJC/QueryYYHXJCList',
	URL_CREATE_BILL = '/Scm/YYHXJC/GenBill',
	URL_ELIMINATE = '/Scm/YYHXJC/Eliminate',
	URL_GET_CONFIRM_LIST = '/Scm/MSQR/QueryMSQRList',
	URL_GET_CONFIRM_IMG_LIST = '/Scm/MSQR/QueryMSQRImgList',
	URL_GET_TAKE_DELIVERY_LIST = '/Scm/YYCXSH/QueryYYCXSHList',
	URL_TAKE_DELIVERY = '/Scm/YYCXSH/TakeSample',
	URL_TAKE_ONE_DELIVERY = '/Scm/YYCXSH/TakeOneSample',
	URL_BUYER_CHECK = '/Scm/MSQR/BuyerCheck',
	URL_GET_ONECK_LIST = '/Scm/YYYSDF/QueryYYYSDFList',
	URL_GET_SAMPLE_MARK = '/Scm/YYYSDF/GetMark',
	URL_SUBMIT_SAMPLE_MARK = '/Scm/YYYSDF/SubmitMark',
	URL_GET_ONECK_STATUS = '/Scm/YYYSDF/GetOneCkFalg',
	URL_GET_SCORE_ITEM = '/Scm/Dict/GetScoreItem',
	URL_GET_ONE_RESOLVE_LIST = '/Scm/YYYSJC/QueryYYYSJCList',
	URL_GET_SCORE_LIST = '/Scm/YYYSJC/GetScore',
	URL_GET_ROLE_SCORE_LIST = '/Scm/YYYSJC/GetRoleScore',
	URL_SUBMIT_SAMPLE_RESOLVE = '/Scm/YYYSJC/Submit',
	URL_GET_CHECK_STYLE_LIST = '/YYFGQR/QueryYYFGQRList',
	URL_CHECK_STYLE = '/YYFGQR/Edit',
	URL_CHANGE_STATUS = '/Scm/YYHX/ChangeStatus',
	URL_CHANGE_ONECK_STATUS = '/Scm/YYYSDF/ChangeStatus',
	URL_GET_STYLE_LIST = '/Scm/Dict/GetFGCategory',
	URL_GET_MIN_CATEGORY_LIST = '/Scm/Dict/GetMinCategory',
	URL_GET_SECORD_REASON = '/Scm/YYESSP/GetReason'
export default (API = {
  //登录接口
  login(data) {
    return API.get(URL_LOGIN, data )
	},
	wxLogin(data) {
		return API.get(URL_WX_LOGIN,data)
	},
	getMenu(data) {
		return API.get(URL_GET_MENU, data)
	},
	//通用接口
	currency: {
		getSampleDetail(data) {//获取样衣详情
			return API.get(URL_GET_SAMPLE_DETAIL, data)
		},
		getSampleImgs(data) {//获取样衣图片列表
			return API.get(URL_GET_SAMPLE_IMGS, data)
		},
		getColors() {
			return API.get(URL_GET_COLOR)
		},
		getSizes(){
			return API.get(URL_GET_SIZE)
		},
		upload(data) {
			return API.postFile(URL_UPLOAD, data)
		}
	},
	//数据字典
	dic: {
		getBaseBandList: function() {
			return API.get(URL_GET_BASE_BAND_LIST)
		},
		getBaseVenderList: function() {
			return API.get(URL_GET_BASE_VENDER_LIST)
		},
		getBaseStyleList: function() {
			return API.get(URL_GET_BASE_STYLY_LIST)
		},
		getBaseCateGoryList: function() {
			return API.get(URL_GET_BASE_CATEGORY_LIST)
		},
		getMinCateGoryList: function() {
			return API.get(URL_GET_MIN_CATEGORY_LIST)
		},
		getBaseFlagList() {
			return API.get(URL_GET_BASE_FLAG_LIST)
		},
		getPhotoCheckList() {//获取图片审核值列表
			return API.get(URL_GET_PHOTO_CHECK_LIST)
		},
		getStyleList() {
			return API.get(URL_GET_STYLE_LIST)
		}
	},
	//照片审核
	ckphoto: {
		getImgList(data) {
			return API.get(URL_GET_IMG_LIST, data)
		},
		//获取单个样衣审核信息结果
		getSampleCheckList(data) {
			return API.get(URL_GET_SAMPLE_CHECK_LIST, data)
		},
		checkPhoto(data, status) {
			return API.post(URL_CHECK_PHOTO, data, `status=${status}`)
		}
	},
	//样衣海选发布
	push: {
		getList(data) {
			return API.get(URL_GET_PUSH_LIST, data)
		},
		getStatusList() {
			return API.get(URL_GET_PUSH_STATUS_LIST)
		},
		publish(data) {
			return API.post(URL_PUSH_PUBLISH, data)
		},
	},
	//样衣海选
	audit: {
		like(data) {
			return API.get(URL_AUDIT_LIKE, data)
		},
		unlike(data) {
			return API.get(URL_AUDIT_UNLIKE, data)
		},
		list(data) {
			return API.get(URL_GET_AUDIT_LIST, data)
		},
		changeStatus(data) {
			return API.post(URL_CHANGE_STATUS, data)
		}
	},
	//样衣海选决策
	resolve: {
		list(data) {
			return API.get(URL_GET_RESOLVE_LIST, data)
		},
		createBill(data) {
			return API.post(URL_CREATE_BILL, data)
		},
		eliminate(data) {
			return API.post(URL_ELIMINATE, data)
		} 
	},
	//买手确认
	confirm: {
		list(data) {
			return API.get(URL_GET_CONFIRM_LIST, data)
		},
		getImgList(data) {
			return API.get(URL_GET_CONFIRM_IMG_LIST, data)
		},
		buyerCheck(data) {
			return API.post(URL_BUYER_CHECK, data)
		}
	},
	//初选收货
	takeDelivery: {
		list(data) {
			return API.get(URL_GET_TAKE_DELIVERY_LIST, data)
		},
		takeDelivery(data) {
			return API.post(URL_TAKE_DELIVERY, data)
		},
		takeOneDelivery(data) {
			return API.post(URL_TAKE_ONE_DELIVERY, data)
		}
	},
	oneck: {
		list(data) {
			return API.get(URL_GET_ONECK_LIST, data)
		},
		getSampleMark(data) {
			return API.get(URL_GET_SAMPLE_MARK, data)
		},
		submitSampleMark(data) {
			return API.post(URL_SUBMIT_SAMPLE_MARK, data)
		},
		getStatus() {
			return API.get(URL_GET_ONECK_STATUS)
		},
		getScoreItem() {
			return API.get(URL_GET_SCORE_ITEM)
		},
		changeStatus(data) {
			return API.post(URL_CHANGE_ONECK_STATUS, data)
		}
	},
	//一审决策
	oneresolve: {
		list(data) {
			return API.get(URL_GET_ONE_RESOLVE_LIST, data)
		},
		getScoreList(data) {
			return API.get(URL_GET_SCORE_LIST, data)
		},
		getRoleScoreList(data) {
			return API.get(URL_GET_ROLE_SCORE_LIST, data)
		},
		submit(data) {
			return API.get(URL_SUBMIT_SAMPLE_RESOLVE, data)
		}
	},
	//样衣风格确认
	checkstyle: {
		list(data) {
			return API.get(URL_GET_CHECK_STYLE_LIST, data)
		},
		checkstyle(data) {
			return API.post(URL_CHECK_STYLE, data)
		}
	},
	//证件相关
	certificate: {
		getSupplierCertificateDetail: function(data) {
			return API.get(URL_GET_SUPPLIER_CERTIFICATE_DETAIL,data)
		},
		getSupplierCertificateList: function(data) {
			return API.get(URL_GET_SUPPLIER_CERTIFICATE_LIST,data)
		},
	},
	//波段相关
	band: {
		getBandList: function(data) {
			return API.get(URL_BAND_LIST, data)
		},
		getBandDetail: function(data) {
			return API.get(URL_BAND_DETAIL, data)
		},
		create(data) {
			return API.post(URL_BAND_CREATE, data)
		},
		edit(data) {
			return API.post(URL_BAND_EDIT, data)
		},
		submit(data) {
			return API.get(URL_BAND_SUBMIT, data)
		},
		getStateTree() {
			return API.get(URL_GET_STATE_TREE)
		},
		getWorkState(data) {
			return API.get(URL_GET_WORK_STATE, data)
		}
	},
	//样衣初选单
	primary: {
		getPrimaryList(data) { return API.get(URL_GET_PRIMARY_LIST, data) },
		getPrimaryDetail(data) {
			return API.get(URL_GET_PRIMARY_DETAIL, data)
		},
		getPrimaryExpress (data) {
			return API.get(URL_GET_PRIMARY_EXPRESS, data)
		},
		//发快递
		sendSample(data) {
			return API.get(URL_SEND_SAMPLE, data)
		},
		submitDetail(data) {
			return API.post(URL_SUBMIT_DETAIL, data)
		},
		getExpressList() { return API.get(URL_GET_EXPRESS) }
	},
	eliminate: {//淘汰样衣
		getEliminateList(data) {
			return API.get(URL_GET_ELIMINATE_LIST, data)
		},
		//收快递
		takeSample(data) {
			return API.post(URL_TACK_SAMPLE, data)
		},
		takeOneSample(data) {
			return API.post(URL_TACK_ONE_SAMPLE, data)
		}
	},
	//二审资料补充
	secondInstance: {
		getList(data) {
			return API.get(URL_GET_SECONDE_INSTANCE_LIST, data)
		},
		save(data) {
			return API.post(URL_GET_SECONDE_INSTANCE_SAVE, data)
		},
		getReason(data) {
			return API.get(URL_GET_SECORD_REASON, data)
		}
	},
	//样衣申请
	apply: {
		getApplyList(data) {
			return API.get( URL_GET_APPLY_LIST, data)
		}
	},
	weixin: {
		getCode(...rest) {
			

		}
	},
  get (url, data) {
    return new Promise((resole,reject)=>{
			let u = `${BASE_URL}/${url}?token=${store.state.token}`
			axios.get(u,{ params: data }).then( response => {
				resole(response.data)
			}).catch( response => {
				console.log('网络不通！', response)
			});
		})
	},
	post (url, data, getData) {
		const config = { headers: {
			'Content-type': 'application/x-www-form-urlencoded'
		}}
		return this.postData(url, data, config, getData)
	},
	postData(url, data, config, getData) {
		const start = new Date().getTime()
		return new Promise((resole,reject)=>{
			let u = `${BASE_URL}/${url}?token=${store.state.token}&${getData}`
			axios.post(u, data, config)
			.then( response => {
				const end = new Date().getTime()
				resole(response.data)
			}).catch( response => {
				Toast({
					message: '请求耗时:'+(end-start)+',请求失败'+JSON.stringify(response),
					duration: '4000'
				})
				console.log('网络不通！', response)
			})
		})
	},
	postFile (url, data, callback ) {
    	const formData = new FormData()
		formData.append('file', data)
    	return this.postData(url, formData)
  },
})
